package com.star.warmwinter.module.user.ui;

import android.databinding.DataBindingUtil;
import android.graphics.drawable.Drawable;

import com.star.tool.util.SizeUtils;
import com.star.warmwinter.R;
import com.star.warmwinter.common.BaseActivity;
import com.star.warmwinter.databinding.CommonLoginCodeBinding;
import com.star.warmwinter.module.user.viewCtrl.ForgetPwdCtrl;
import com.star.warmwinter.module.user.viewCtrl.LoginCtrl;
import com.star.warmwinter.module.user.viewCtrl.RegisterCtrl;

import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_FORGET_PWD;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_KEY;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_LOGIN;
import static com.star.warmwinter.module.user.ui.CommonLoginTelActivity.LOGIN_TYPE_REGISTER;

/**
 * Author: blackbai11
 * Date: 2018/5/31
 * Description: 通用手机验证码登录逻辑页面(登录,注册,忘记密码)
 */
public class CommonLoginCodeActivity extends BaseActivity {

    private CommonLoginCodeBinding mBinding;

    @Override
    public void bindLayout() {
        setContentView(R.layout.common_login_code);
        mBinding = DataBindingUtil.setContentView(this, R.layout.common_login_code);
    }

    @Override
    public void doBusiness() {
        //设置验证码图标大小
        Drawable drawable = getResources().getDrawable(R.mipmap.icon_code);
        drawable.setBounds(0, 0, SizeUtils.dp2px(21), SizeUtils.dp2px( 16));
        mBinding.tvNoticeCode.setCompoundDrawables(drawable, null, null, null);

        int type = getIntent().getIntExtra(LOGIN_TYPE_KEY, -1);
        switch (type) {
            case LOGIN_TYPE_REGISTER:
                mBinding.titleBar.setTitle("注册");
                mBinding.setCommonLoginCtrl(new RegisterCtrl(this, mBinding));
                break;

            case LOGIN_TYPE_LOGIN:
                mBinding.titleBar.setTitle("登录");
                mBinding.setCommonLoginCtrl(new LoginCtrl(this));
                break;

            case LOGIN_TYPE_FORGET_PWD:
                mBinding.titleBar.setTitle("忘记密码");
                mBinding.setCommonLoginCtrl(new ForgetPwdCtrl(this, mBinding));
                break;
        }
    }
}
